<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <!-- 满足有些用户在手机端访问的需要 -->

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">

    <title>分类专题管理</title>
    <!-- 线上环境 -->
    <link rel="stylesheet" href="/static/css/dist/component-min.css?v=1">
    <link rel="stylesheet" href="/static/plugins/jbox/jbox-min.css">

    <!--vue-->
    <script src="/static/vue/vue.js"></script>
    <!--element ui-->
    <script src="/static/element/index.js"></script>
    <link rel="stylesheet" href="/static/element/index.css">
    <style>
        .el-table__empty-block {
            height: 0;
        }
    </style>

</head>
<body class="cp-bodybox">
<div id="app">
    <#include "/common/header-fg.html" />

    <div class="container">
        <div class="inner clearfix">
            <#include "/common/left-menu-fg.html" />

            <div class="content-right">
                <h1 class="content-right-title">分类专题管理</h1>
                <div style="height: 5px"></div>
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span style="line-height: 36px;">筛选区</span>
                        <div style="float: right">
                            <el-button type="primary" @click.native.prevent="getList">查询</el-button>
                            <el-button type="primary" @click.native.prevent="clearSearch">清空查询条件</el-button>
                        </div>
                    </div>
                    <el-form :inline="true"  label-width="80px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="名称">
                                    <el-input placeholder="请输入名称" v-model="search.name"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="状态">
                                    <el-select v-model="search.enable" placeholder="请选择状态">
                                        <el-option
                                                v-for="item in enableList"
                                                :label="item.label"
                                                :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="创建时间">
                                    <el-date-picker
                                            v-model="search.insertTimeStart"
                                            type="date"
                                            placeholder="选择日期">
                                    </el-date-picker>&nbsp;至&nbsp;
                                    <el-date-picker
                                            v-model="search.insertTimeEnd"
                                            type="date"
                                            placeholder="选择日期">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-card>
                <el-card class="box-card" style="margin-top:10px;">
                    <div slot="header" class="clearfix" v-if="isPermission('catSubject:add', user.permissions)">
                        <el-button type="primary" @click.native.prevent = "add">添加</el-button>
                    </div>
                    <el-table
                            :data="specialList"
                            border
                            style="width: 100%">
                        <el-table-column
                                type="index"
                                label="序号"
                                width="80">
                        </el-table-column>
                        <el-table-column
                                prop="name"
                                label="专题名称"
                                width="180">
                        </el-table-column>
                        <el-table-column
                                prop="enable"
                                align="center"
                                :formatter="formatterEnable"
                                show-overflow-tooltip
                                label="状态">
                        </el-table-column>
                        <el-table-column
                                prop="realName"
                                label="创建人">
                        </el-table-column>
                        <el-table-column
                                prop="insertTime"
                                align="center"
                                :formatter="formatterTime"
                                label="创建时间">
                        </el-table-column>
                        <el-table-column
                                align="center"
                                label="操作"
                                inline-template
                                width="180">
                            <div style="margin-left: -10px">
                                <el-dropdown>
                                    <el-button size="small" type="primary">
                                        操作<i class="el-icon-caret-bottom el-icon--right"></i>
                                    </el-button>
                                    <el-dropdown-menu slot="dropdown" align="center">
                                        <!--<el-dropdown-item v-if="isPermission('catSubject:preview', user.permissions)"><el-button size="mini" type="primary">预览</el-button></el-dropdown-item>-->
                                        <el-dropdown-item v-if="isPermission('catSubject:edit', user.permissions)"><el-button size="mini" type="primary" @click.native.prevent="edit(row.id)">编辑</el-button></el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('catSubject:view', user.permissions)"><el-button size="mini" type="primary" @click.native.prevent="detail(row.id)">详情</el-button></el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('catSubject:enable', user.permissions)">
                                            <el-button size="mini" type="primary" v-if="row.enable === 0" @click.native.prevent="enable(row)">启用</el-button>
                                            <el-button size="mini" type="primary" v-else @click.native.prevent="enable(row)">禁用</el-button>
                                        </el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('catSubject:delete', user.permissions)"><el-button size="mini" type="primary" @click.native.prevent="confirmDeleteItem(row.id)">删除</el-button></el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('catSubject:up', user.permissions)"><el-button size="mini" v-if="$index !== 0" @click.native.prevent="up(row.id)" type="primary">上移</el-button></el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </div>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                            :current-page="currentPage"
                            @current-change="handleCurrentChange"
                            :page-size="pageSize"
                            layout="total,prev, pager, next"
                            :total="totalCount">
                    </el-pagination>
                </el-card>
            </div>
            <!-- end content-right -->

            <a href="javascript:;" class="btn-leftMenuFold" id="j-btn-leftMenuFold"></a>
        </div>
    </div>
    <!-- end container -->

    <!--gonggao-->

    <!--tip-->
    <div class="footer">© 2017 , Inc. All rights reserved.</div>
    <!-- end footer -->
    <div class="fixedBar" style="right: -78px;">
        <ul>
            <template v-for="(item, index) in leftMenuList">
                <li v-if="index==0" :class="'shopManager' + index + ' cur'"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
                <li v-else :class="'shopManager' + index"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
            </template>
        </ul>
        <a href="javascript:;" class="fixedBar-btn" id="j-fixedBar-btn"></a>
    </div>
    <a href="#" id="j-gotop" class="gotop" title="回到顶部" style="left: 1920.59px;"></a>

</div>
<script src="/static/js/dist/lib-min.js"></script>
<script src="/static/js/dist/component-min.js"></script>

<!-- 引入列表数据 -->
<script src="/static/js/dist/list.js"></script>

<!-- 引入vue组件 -->
<script src="/static/js/dist/vueComponents.js"></script>

<!-- 引入api -->
<script src="/static/js/api.js"></script>

<!-- 引入共通js -->
<script src="/static/js/common.js"></script>
<script>
    var vm = new Vue({
        el: '#app',
        mounted: function () {
            this.getList();
        },
        methods: {
            add() {
                window.location.href = "/special/type/add"
            },
            edit (id) {
                window.location.href = "/special/type/edit?specialId=" + id;
            },
            detail (id) {
                window.location.href = "/special/type/detail?specialId=" + id;
            },
            enable (row) {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                if (row.enable === 0) { // 启用
                    this.http("/special/enable", {id: row.id}, function (res) {
                        if (res.status === 200) {
                            loading.close();
                            row.enable = 1;
                        } else {
                            loading.close();
                            that.$alert(res.errMsg, '提示', {
                                confirmButtonText: '确定',
                            });
                        }
                    }, function (res) {
                        loading.close();
                        that.$alert('服务器错误', '提示', {
                            confirmButtonText: '确定',
                        });
                    })
                } else { // 禁用
                    this.http("/special/disable", {id: row.id}, function (res) {
                        if (res.status === 200) {
                            loading.close();
                            row.enable = 0;
                        } else {
                            loading.close();
                            that.$alert(res.errMsg, '提示', {
                                confirmButtonText: '确定',
                            });
                        }
                    }, function (res) {
                        loading.close();
                        that.$alert('服务器错误', '提示', {
                            confirmButtonText: '确定',
                        });
                    })
                }

            },
            formatterTime (row, column) {
                if (row.insertTime !== undefined && (row.insertTime + "").length >= 10) {
                    return (row.insertTime + "").substring(0, 10);
                } else {
                    return row.insertTime;
                }
            },
            confirmDeleteItem (id) {
                let that = this;
                this.$confirm('此操作将删除该专题, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(function () {
                    that.deleteSpecial(id);
                }).catch(function () {
                    that.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            deleteSpecial (id) {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                this.http("/special/delete", {id: id}, function (res) {
                    if (res.status === 200) {
                        loading.close();
                        that.getList();
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                            closeOnClickModal: false
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('服务器错误', '提示', {
                        confirmButtonText: '确定',
                        closeOnClickModal: false
                    });
                })
            },
            formatterEnable (row, column) {
                let enable = row.enable;
                if (enable === 0) {
                    return '禁用';
                } else {
                    return '启用';
                }
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.getList();
            },
            up (id) {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                this.http("/special/type/up", {id: id}, function (res) {
                    if (res.status === 200) {
                        loading.close();
                        that.getList();
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('上移失败','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            clearSearch () {
                this.search = {
                    name: '',
                    enable: '',
                    insertTimeEnd: '',
                    insertTimeStart: ''
                }
                this.getList();
            },
            getList () {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true, text: '加载中'});
                let obj = {
                    name: this.search.name,
                    insertTimeStart: this.formatTime(this.search.insertTimeStart, true),
                    insertTimeEnd: this.formatTime(this.search.insertTimeEnd, true),
                    enable: this.search.enable,
                    currentPage: this.currentPage,
                    pageSize: this.pageSize,
                    isAll: 0
                }
                this.http("/special/type/list", obj, function (res) {
                    if (res.status === 200) {
                        loading.close();
                        that.specialList = res.data.list;
                        that.totalCount = res.data.total
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('服务器错误', '提示', {
                        confirmButtonText: '确定',
                    });
                })
            }
        },
        data: function(){
            return {
                formLabelWidth: '100px',
                search: {
                    name: '',
                    enable: '',
                    insertTimeEnd: '',
                    insertTimeStart: ''
                },
                user: ${(user)!'null'},
                enableList: [
                    {
                        label: '启用',
                        value: 1
                    },
                    {
                        label: '禁用',
                        value: 0
                    }
                ],
                headerNavList: list.headerNavList,
                accountNavList: list.accountNavList,
                specialList: [],
                currentPage: list.currentPage,
                pageSize: list.pageSize,
                totalCount: 0,
                leftMenuList: list.menu
            }
        }
    })
</script>

<!-- 20170105 --></body>
</html>